﻿Public Class LoginForm


    Private strServerName As String = ""
    Private strAuthenticationType As String = ""
    Private strSQLUserverName As String = ""
    Private strSQLPassword As String = ""
    Private boolIsApplyToAll As Boolean

    Public Property ServerName() As String
        Get
            Return strServerName
        End Get
        Set(value As String)
            strServerName = value
        End Set
    End Property

    Public Property AuthenticationType() As String
        Get
            Return strAuthenticationType
        End Get
        Private Set(value As String)
            strAuthenticationType = value
        End Set
    End Property

    Public Property SQLUserverName() As String
        Get
            Return strSQLUserverName
        End Get
        Private Set(value As String)
            strSQLUserverName = value
        End Set
    End Property

    Public Property SQLPassword() As String
        Get
            Return strSQLPassword
        End Get
        Private Set(value As String)
            strSQLPassword = value
        End Set
    End Property

    Public Property IsApplyToAll() As Boolean
        Get
            Return boolIsApplyToAll
        End Get
        Private Set(value As Boolean)
            boolIsApplyToAll = value
        End Set
    End Property


    ' TODO: Insert code to perform custom authentication using the provided username and password 
    ' (See http://go.microsoft.com/fwlink/?LinkId=35339).  
    ' The custom principal can then be attached to the current thread's principal as follows: 
    '     My.User.CurrentPrincipal = CustomPrincipal
    ' where CustomPrincipal is the IPrincipal implementation used to perform authentication. 
    ' Subsequently, My.User will return identity information encapsulated in the CustomPrincipal object
    ' such as the username, display name, etc.

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click

        'Validation of fields

        If cmbAuthenticationType.Text = "" Then
            MsgBox("Please select Authentication Type!", MsgBoxStyle.Information Or MsgBoxStyle.OkOnly, "Warning!")
            cmbAuthenticationType.Focus()
            Return
        End If
        ServerName = txtServerName.Text
        AuthenticationType = cmbAuthenticationType.SelectedText
        If Not cmbAuthenticationType.Text = "Windows Authentication" Then

            If UsernameTextBox.Text = "" Then
                MsgBox("Please type User Name !", MsgBoxStyle.Information Or MsgBoxStyle.OkOnly, "Warning!")
                UsernameTextBox.Focus()
                Return
            End If

            If PasswordTextBox.Text = "" Then
                MsgBox("Please type Password!", MsgBoxStyle.Information Or MsgBoxStyle.OkOnly, "Warning!")
                PasswordTextBox.Focus()
                Return
            End If

           
            SQLPassword = PasswordTextBox.Text
            SQLUserverName = UsernameTextBox.Text
           
        End If
        If chkApplyAll.Checked Then
            IsApplyToAll = True
        Else
            IsApplyToAll = False
        End If
        Me.Close()
    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Me.Close()
    End Sub

    Private Sub LoginForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        cmbAuthenticationType.Text = "Windows Authentication"
    End Sub

    
    Private Sub cmbAuthenticationType_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbAuthenticationType.SelectedIndexChanged
        If cmbAuthenticationType.Text = "Windows Authentication" Then
            AuthenticationType = "Windows Authentication"
            UsernameTextBox.BackColor = Color.LightGray
            UsernameTextBox.Enabled = False
            PasswordTextBox.BackColor = Color.LightGray
            PasswordTextBox.Enabled = False

        
        Else
            AuthenticationType = "SQL Server Authentication"

            UsernameTextBox.BackColor = Color.White
            UsernameTextBox.Enabled = True
            PasswordTextBox.BackColor = Color.White
            PasswordTextBox.Enabled = True
        End If
    End Sub
End Class
